package tushare

import (
	"tushare/model/mysql"
)

type RaisingLimitStruct struct {
	Id             int64  `json:"id"`
	TsCode         string `json:"ts_code"`
	ContinuousDays int64  `json:"continuous_days"`
}

type RaisingLimitJoinStruct struct {
	Id             int64  `json:"id"`
	TsCode         string `json:"ts_code"`
	ContinuousDays int64  `json:"continuous_days"`
	Name           string `json:"name"`
}

func RaisingLimitCreate(rls RaisingLimitStruct) {
	mysql.DB.Table("tushare_raising_limit").Create(&rls)
}

func RaisingLimitList(day int) []RaisingLimitJoinStruct {
	rls := []RaisingLimitJoinStruct{}
	mysql.DB.Table("tushare_raising_limit").Select(`
		tushare_raising_limit.ts_code as ts_code,
		tushare_raising_limit.continuous_days as continuous_days,
		tushare_stock.name as name
	`).Joins(`
	LEFT JOIN tushare_stock on tushare_raising_limit.ts_code = tushare_stock.ts_code
	`).Where("tushare_raising_limit.continuous_days = ?", day).Find(&rls)
	return rls
}
